from django.test import TestCase

# Create your tests here.
from sqlalchemy import create_engine, Column, Integer, String, Float, Text, DateTime
from sqlalchemy.ext.declarative import declarative_base
from datetime import datetime

from sqlalchemy.orm import sessionmaker

# 创建基类
Base = declarative_base()
# 定义数据模型
class Article(Base):
    __tablename__ = 'blog_article'

    id = Column(Integer, primary_key=True)
    title = Column(String(200))
    author = Column(String(100))
    price = Column(Float)
    content = Column(Text)
    pub_date = Column(DateTime)
    status = Column(String(20))
    #描述信息
    description = Column(Text)

    def __repr__(self):
        return (f"<Article(title='{self.title}', "
                f"author='{self.author}', "
                f"price={self.price}, "
                f"pub_date={self.pub_date}, "
                f"description='{self.description}', "
                f"status='{self.status}')>")




if __name__ == '__main__':
    # 创建数据库引擎，请根据实际情况修改连接信息
    engine = create_engine('mysql+mysqlconnector://root:123456@localhost:3306/e_invoiceai')

    # 创建会话工厂
    Session = sessionmaker(bind=engine)
    session = Session()
    #查询文章列表
    articles = session.query(Article).all()
    for article in articles:
        print(article)


